package com.realgodo.site.web.user.mood;

import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.mood.Mood;
import com.realgodo.site.service.application.MoodManager;
import com.realgodo.site.web.user.UserDefaultController;

/**
 * 用户纠结管理
 * 
 * @author ljw E-mail: ssdutljw@163.com
 * @version 创建时间：2009-12-13
 */
@Scope("prototype")
@Result(name = "toindex", type = "redirect", location = "${base}/user/mood/")
public class IndexController extends UserDefaultController {

	/***/
	private static final long serialVersionUID = 5940378462859906421L;

	@Autowired
	private MoodManager moodManager;
	
	/** 纠结分页信息 */
	private Page<Mood> moodPage;
	/** 纠结实体 */
	private Mood mood;
	

	@Override
	public String execute() throws Exception {
		super.getParamMap().put("spaceId", super.getSpace().getId().toString());
		return list();
	}

	public String friends() {
		super.getParamMap().put("spaceIds",friendManager.getFriendSpaceIdList(super.getSpace().getId()));
		return list();
	}

	public String list(){
		this.moodPage = moodManager.find(PAGE_SIZE, super.getParamMap());
		super.setPageInfo(moodPage);
		return SUCCESS;
	}
	
	
	/** 发布纠结 */
	public String pub() {
		mood.setSpace(super.getSpace());
		mood = moodManager.saveMood(mood);
		return "toindex";
	}
	
	public String detail(){
		this.mood=moodManager.get(id);
		return "detail";
	}

	public String delete(){
		moodManager.delete(id);
		return "toindex";
	}
	// -------------get/set----------//

	public Page<Mood> getMoodPage() {
		return moodPage;
	}



	public Mood getMood() {
		return mood;
	}

	public void setMood(Mood mood) {
		this.mood = mood;
	}

}
